package at.sysarch.filter;

import java.io.File;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

import at.pimpmypipe.filter.DataEnrichmentFilter;
import at.sysarch.bean.AbstractBean;
import at.sysarch.domain.TransferImage;

public class StoreFilter extends DataEnrichmentFilter<TransferImage, TransferImage> {
	
	private File _file;
	
	public StoreFilter(AbstractBean<StoreFilter> bean) {
		super(bean);
	}

	@Override
	protected boolean fillEntity(TransferImage nextVal, TransferImage entity) {
		PlanarImage oldImage;
		oldImage = nextVal.getModifiedImage();	
		JAI.create("filestore", oldImage, _file.getAbsolutePath(), "JPEG");
		
		entity.setModifiedImage(oldImage);
		entity.setSourceImage(nextVal.getSourceImage());
		
		_bean.displayImage(entity);
		return true;
	}

	@Override
	protected TransferImage getNewEntityObject() {
		return new TransferImage();
	}

	public File getFile() {
		return _file;
	}

	public void setFile(File file) {
		_file = file;
	}

}
